package com.example.vertification.config;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry){
//        registry.addInterceptor(new LoginInterceptor()).addPathPatterns("/getindex/**");
//
    }




    public void addCorsMappings(CorsRegistry registry) {
        //addMapping 添加可跨域的请求地址
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(false)
                .allowedMethods("GET","POST","DELETE","PUT","OPTIONS","HEAD")
                .maxAge(3600);
    }

    @Value("${img-path}")
    private String imgPath;


    @Value("${pages-img-path}")
    private String pageimagesPath;

    @Value("${shop-img-path}")
    private  String shops_head;

    @Value("${item-img-path}")
    private  String item_images;

    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("swagger-ui.html")
                .addResourceLocations("classpath:/META-INF/resources/swagger-ui.html");
        registry.addResourceHandler("/webjars/**")
                .addResourceLocations("classpath:/META-INF/resources/webjars/");

        registry.addResourceHandler("/img/**")
                .addResourceLocations(imgPath);


        registry.addResourceHandler("/pages_image/**")
                .addResourceLocations(pageimagesPath);

        registry.addResourceHandler("/shop_head/**")
                .addResourceLocations(shops_head);


        registry.addResourceHandler("/item_images/**")
                .addResourceLocations(item_images);



    }
    
    
    
    
    
    
    
    



}
